<?php

/**
 * 名称：IndexAction
 * 描述：后台首页管理
 * 作者：lan 时间：2013-05-02
 * 版本号：V1.0.0
 * ========================历史版本=================================
 * 序号	 版本号 	日期			姓名	 	描述
 * 1 	V1.0.0 	2013-05-02 	lan  	后台首页管理
 * ========================历史版本=================================
 * 说明：请在有更改程序的时候修改以上注释
 */
class IndexAction extends CommonAction {

    /**
     * 框架首页
     * Create Data <2013-05-02>
     */
    public function index() {
        if (isset($_SESSION['mid'])) {
            $admin = model('User')->where("admin_level='1' and uid=" . $_SESSION['mid'])->find();
        }
        if (empty($admin) && cookie("ylsnsmid")) {
            $admin = model('User')->where("admin_level='1' and uid=" . cookie("ylsnsmid"))->find();
            //增加添加session
            if (!empty($admin)) {
                $_SESSION [C('USER_AUTH_KEY')] = $admin ['uid'];
                $_SESSION ['loginUserName'] = $admin ['uname'];
                $_SESSION['mid'] = $admin['uid'];
                $_SESSION['uname'] = $admin['uname'];
                $_SESSION ['administrator'] = true;
                if (in_array($admin['uid'], C('NOT_AUTH_ADMIN'))) {
                    $_SESSION[C('ADMIN_AUTH_KEY')] = $admin['uid'];
                }
            }
        }
        if (!empty($admin)) {
            $res = $this->top();
            $this->assign('arr', $res['arr']);
            $this->assign('top', $res['top']);
            $this->assign('menu', $this->menu());
            $topArr_keys = array_keys($res['top']);
            $this->assign("show", $topArr_keys[0]);
            $this->display();
        } else {
            $this->display('Public:login');
        }
    }

    /**
     * 顶部页面
     * Create Data <2013-05-02>
     */
    protected function top() {
        $list = array(
            'index' => L('home'),
            'global' => L('global'),
            'ui' => L('ui'),
            'content' => L('content'),
            'user' => L('user'),
            'apps' => L('apps'),
            'plugin' => L('plugin'),
            'site' => '门户',
            'block' => '区块'
        );
        //$sitelist = M('cms_site')->order('siteid')->select();
        $arr = array();
        /* foreach ($sitelist as $k => $v) {
          $list[$v['name']] = $v['name'];
          $arr[$v['name']] = $v['siteid'];
          } */

        $topMenu = $this->_getTopMenu();
        if (!empty($topMenu)) {
            foreach ($topMenu as $k => $v) {
                $topMenu[$k] = strtolower($v["name"]);
            }
            foreach ($list as $k => $v) {
                if (in_array($k, $topMenu)) {
                    continue;
                } else {
                    unset($list[$k]);
                }
            }
        }

        $res = array(
            'top' => $list,
            'arr' => $arr,
        );
        return $res;
    }

    // 菜单页面
    protected function menu() {
        // 显示菜单项
        $menu = array();
        // 后台管理首页
        if (SITE_DOMAIN == "oceanx.yonglang.co") {
            $menu['index'] = array(
                L('home') => array(
                    '基本信息' => URL('admin/Update/main'),
                    L('cacheClean') => URL('admin/Index/cleanRuntime'),
                    '版本升级' => URL('admin/Update/index'),
                    '发布版本' => URL('admin/PublishVersion/index')
                ),
            );
        } else {
            $menu['index'] = array(
                L('home') => array(
                    '基本信息' => URL('admin/Update/main'),
                    L('cacheClean') => URL('admin/Index/cleanRuntime'),
                ),
            );
        }
        $menu ['global'] = array(
            L('global') => array(
                L('siteConfig') => URL('admin/Global/siteopt'),
                L('seoConfig') => URL('admin/Global/siteseo'),
                '导航配置' => URL('admin/Global/nav'),
                L('domainConfig') => URL('admin/Global/domain'),
                L('registerConfig') => URL('admin/Global/register'),
                //L ( 'invite' ) => URL( 'admin/Global/invite' ),
                L('guanshuiConfig') => URL('admin/Global/guanshui'),
                L('creditConfig') => URL('admin/Global/credit'),
                L('announcementConfig') => URL('admin/Global/announcement'),
                L('emailConfig') => URL('admin/Global/email'),
                L('attachConfig') => URL('admin/Global/attachconfig'),
                L('documentConfig') => URL('admin/Global/document'),
                L('auditConfig') => URL('admin/Global/audit'),
                L('weiboConfig') => URL('admin/Global/weibo'),
                L('areaConfig') => URL('admin/Global/area'),
                'Api配置' => URL('api/Admin/config'),
                '附近功能配置' => URL('admin/Global/imagenearConfig'),
                '网站通信' => URL('admin/Site/siteManager'),
                '导入数据' => URL('admin/CopyDB/importData'),
            ),
        );

        $menu ['ui'] = array(
            L('ui') => array(
                L('styleManage') => URL('admin/Ui/style'),
                '门户风格列表' => URL('cms/Site/style'),
                L('expressionManage') => URL('admin/Ui/expression'),
                L('editorSettings') => URL('admin/Ui/editor')
            ),
        );

        $menu ['content'] = array(
            L('content') => array(
                L('adManage') => URL('admin/Content/ad'),
                '微博管理' => URL('admin/Content/weibo'),
                '话题管理' => URL('admin/Content/topic'),
                L('attachManage') => URL('admin/Content/attach'),
                '消息照片' => URL('admin/MessPhoto/messphotolist'),
                L('commentManage') => URL('admin/Content/comment'),
                L('messageManage') => URL('admin/Content/message'),
                L('notifyManage') => URL('admin/Content/notify'),
                L('feedManage') => URL('admin/Content/feed'),
                L('denounceManage') => URL('admin/Content/denounce'),
                L('adminlogManage') => URL('admin/Content/adminlog'),
                '标签管理' => URL('admin/Content/tag'),
                '注册码管理' => URL('admin/Content/apply'),
                '反馈信息管理' => URL('admin/Content/feedback'),
            ),
        );

        $menu ['user'] = array(
            L('user') => array(
                L('userManage') => URL('admin/User/user'),
                L('userGroupManage') => URL('admin/User/userGroupManage'),
                '商圈管理' => URL('admin/Circle/circlelist'),
                L('dataConfig') => URL('admin/User/dataConfig'),
                L('massNews') => URL('admin/User/massNews'),
                L('inviteStatis') => URL('admin/User/inviteStatis'),
                L('loginLog') => URL('admin/User/loginLog'),
                L('nodeManage') => URL('admin/User/nodeManage'),
                "推送配置" => URL('admin/Push/pushConfig'),
                "推送中心" => URL('admin/Push/syspush'),
            ),
        );

        $menu ['apps'] = array(
            L('apps') => array(
                L('appsList') => URL('admin/Apps/appsList'),
                L('appsInstall') => URL('admin/Apps/appsInstall')
            ),
        );

        $apps = model("App")->getAdminApp('app_name,app_alias,admin_entry');
        foreach ($apps as $v) {
            $menu ['apps'][L('apps')] [$v ['app_alias']] = URL($v ['app_name'] . '/' . $v ['admin_entry']);
        }

        $menu ['plugin'] = array(
            L('plugin') => array(
                L('installPlugin') => URL('admin/Plugin/installPlugin'),
                L('waitInstallPlugin') => URL('admin/Plugin/waitInstallPlugin')
            ),
        );

        $addons = M('Addons');
        $list = $addons->where("isMenu='1'")->select();
        foreach ($list as $k => $v) {
            $menu ['plugin'][L('plugin')] [$v ['pluginName']] = URL('admin/Plugin/adminMenu', array(
                'name' => $v ['name']
            ));
        }

        $menu ['site'] = array(
            L('manager') => array(
                L('siteManager') => URL('cms/Site/index'),
                '内容列表' => URL('cms/Article/contentlist'),
                '栏目管理' => URL('cms/Cate/sitecatelist'),
                '内容分类' => URL('cms/Article/contentmodel'),
                '模板管理' => URL('cms/Template/sitetemplatelist'),
                '生成首页' => URL('cms/Create/create_home'),
                '生成栏目页' => URL('cms/Create/create_cate'),
                '生成内容页' => URL('cms/Create/create_content'),
                '栏目分组管理' => URL('cms/Group/sitegrouplist', array("type" => 0)),
                '内容分组管理' => URL('cms/Group/sitegrouplist', array("type" => 1)),
                '配置管理' => URL('cms/Config/siteconfiglist'),
                //'区块分类' => URL('cms/BlockClassify/classify'),
                '回收站' => URL('cms/Article/deletecontentlist')
            ),
        );

        $sitelist = M('cms_site')->order('siteid')->select();
        if (!empty($sitelist)) {
            foreach ($sitelist as $k => $v) {
                $menu[$v['name']] = array(
                    $v['name'] => array(
                        $v['name'] . '_内容列表' => URL('cms/Article/contentlist'),
                        $v['name'] . '_栏目列表' => URL('cms/Cate/catelist'),
                        $v['name'] . '_内容分类' => URL('cms/Article/contentmodel'),
                        $v['name'] . '_模版管理' => URL('cms/Template/sitetemplatelist'),
                        $v['name'] . '_生成首页' => URL('cms/Create/create_home', array('sid' => $v['siteid'])),
                        $v['name'] . '_批量生成栏目页' => URL('cms/Create/create_cate'),
                        $v['name'] . '_批量生成内容页' => URL('cms/Create/create_content'),
                        $v['name'] . '_栏目分组管理' => URL('cms/Group/group', array('type' => 0)),
                        $v['name'] . '_内容分组管理' => URL('cms/Group/group', array('type' => 1)),
                        $v['name'] . '_配置' => URL('cms/Config/siteconfiglist'),
                    ),
                );
            }
        }

        $roleMenu = $this->_getMenu();
        if (!empty($roleMenu)) {
            foreach ($roleMenu as $k => $v) {
                $roleMenu[$k] = $v["text"];
            }
            foreach ($menu as $k => $menu1) {
                foreach ($menu1 as $k1 => $menu2) {
                    foreach ($menu2 as $k2 => $v) {
                        if (in_array($k2, $roleMenu)) {
                            continue;
                        } else {
                            unset($menu[$k][$k1][$k2]);
                        }
                    }
                }
            }
        }

        foreach ($menu as $k => $menu1) {
            foreach ($menu1 as $k1 => $menu2) {
                foreach ($menu2 as $k2 => $v) {
                    if (strpos($k2, "_") !== false) {
                        $karr = explode("_", $k2);
                        $menu[$k][$k1][$karr[1]] = $v;
                        unset($menu[$k][$k1][$k2]);
                    }
                }
            }
        }
        return $menu;
    }

    private function _getTopMenu() {
        $rid = M('role_user')->where("user_id =" . $_SESSION['mid'])->field("role_id")->find();
        if ($rid) {
            $data = M('access')->join(" as a left join " . C('DB_PREFIX') . "node as n on a.node_id = n.id")
                            ->where(" a.role_id=" . $rid["role_id"] . " and a.level=2")->field("n.name")->select();
        }
        return $data;
    }

    private function _getMenu() {
        $rid = M('role_user')->where("user_id =" . $_SESSION['mid'])->field("role_id")->select();
        if ($rid) {
        	$ids = "";
        	foreach ($rid as $v){
        		$ids.= $v['role_id'].',';
        	}
        	$ids=substr($ids,0, strlen($ids)-1);
            $data = M('access')->join(" as a left join " . C('DB_PREFIX') . "node as n on a.node_id = n.id")
                            ->where(" a.role_id  in( " . $ids . ") and sid=0")->field("n.title")->select();
        }
        return $data;
    }

    /**
     * 清除系统缓存
     * Create Data <2013-05-02>
     */
    public function cleanRuntime() {
        //清文件缓存
        $dirs = array('./runtime/');
        //清理缓存
        foreach ($dirs as $value) {
            $this->_rmdirr($value);
            //echo "<div class='sys-info'><p>".L('clearedCache')."</p></div>";
        }
        @mkdir('runtime', 0777, true);
        $this->display();
    }

    /**
     * 清除系统缓存
     * Create Data <2013-05-02>
     */
    public function cleanRuntime2() {
        //清文件缓存
        $dirs = array('./runtime/');

        //清理缓存
        foreach ($dirs as $value) {
            $this->_rmdirr($value);
        }

        @mkdir('runtime', 0777, true);
    }

    /**
     * 删除目录文件
     * Create Data <2013-05-02>
     */
    private function _rmdirr($dirname) {
        import('ORG.Io.Dir');
        Dir::delDir($dirname);
        /* if (!file_exists($dirname)) {
          return false;
          }
          if (is_file($dirname) || is_link($dirname)) {
          return unlink($dirname);
          }
          $dir = dir($dirname);
          while (false !== ($entry = $dir->read())) {
          if(in_array($entry,array('.','..')))continue;
          if(is_dir($dirname . DIRECTORY_SEPARATOR . $entry)) {
          $this->_rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
          }
          $this->_rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
          }
          $dir->close();
          return rmdir($dirname); */
    }

    /**
     * 菜单数据
     * guang
     */
    protected function menu3() {
        // 显示菜单项
        $menu = array();
        $menutree = array();
        // 后台管理首页

        $menu[1] = array(
        		'text' => L('home'),
        		'label' => 'home',
        		'tab1' => array(
        				'text' => '首页',
        				'label' => 'home',
        				'children' => array(
        						array('text' => '基本信息', 'url' => URL('admin/Update/main')),
        				),
        		),
        );
        $menu[2] = array(
        		'text'  => '用户',
        		'label' => 'user',
        		'tab1'  => array(
        				'text' => '用户',
        				'label' => 'user',
        				'children' => array(
        						  array('text' => L('userManage'), 'url' => URL('admin/User/user')),
                             //     array('text' => '用户黑名单', 'url' => URL('admin/Blacklist/blacklist')),
                                  array('text' => L('userGroupManage'), 'url' => URL('admin/User/userGroupManage')),
                           //       array('text' => L('dataConfig'), 'url' => URL('admin/User/dataConfig')),
                                //  array('text' => L('massNews'), 'url' => URL('admin/User/massNews')),
                                //  array('text' => L('inviteStatis'), 'url' => URL('admin/User/inviteStatis')),
                                  array('text' => L('loginLog'), 'url' => URL('admin/User/loginLog')),
//         						  array(
//         								'text' => '推送',
//         								'label' => 'push',
//         								'children' => array(
//         										 array('text' => "推送中心", 'url' => URL('admin/Push/syspush')),
//                                                  array('text' => "推送配置", 'url' => URL('admin/Push/pushConfig')),
//         							            ),
//         						  		)
        				),
        		),
        		 
        
        );
        
        
        $menu[3] = array(
        		'text' => '门户',
        		'label' => 'portal',
        		'tab1' => array(
        				'text' => '内容列表',
        				'label' => 'cms',
        				'children' => array(),
        		),
        		'tab2' => array(
        				'text' => '站长',
        				'label' => 'manager',
        				'children' => array(
        						  array('text' => L('siteManager'), 'url' => URL('cms/Site/index')),
                                  array('text' => '栏目管理', 'url' => URL('cms/Cate/catelist')),
                                  array('text' => '内容分类', 'url' => URL('cms/Article/contentmodel')),
                                  array('text' => '模板管理', 'url' => URL('cms/Template/sitetemplatelist')),
        						  array(
        						  		'text' => '生成管理',
        						  		'label' => 'create',
        						  		'children' => array(
        						  				          array('text' => '生成首页', 'url' => URL('cms/Create/create_home')),
                                                          array('text' => '生成栏目页', 'url' => URL('cms/Create/create_cate')),
                                                          array('text' => '生成内容页', 'url' => URL('cms/Create/create_content')),
        						  		),
        						  ),
                                  array('text' => '栏目分组管理', 'url' => URL('cms/Group/sitegrouplist', array("type" => 0))),
                                  array('text' => '内容分组管理', 'url' => URL('cms/Group/sitegrouplist', array("type" => 1))),
                                  array('text' => '站点配置管理', 'url' => URL('cms/Config/siteconfiglist')),
        						  array(
        								'text' => '站内链接配置',
        								'label' => 'textLink',
        								'children' => array(
        										 array('text' => '站内链接管理', 'url' => URL('cms/TextLink/textLink')),  
        										 array('text' => '站内链接配置', 'url' => URL('cms/TextLink/linkConfig')),
        								),
        						  ),
                                  array('text' => '又拍云配置', 'url' => URL('cms/Config/yunconfig')),
        						 // array('text' => '蜘蛛分析', 'url' => URL('admin/Searcher/searcher')),
                                  array('text' => '回收站', 'url' => URL('cms/Article/deletecontentlist')),
        				),
        
        
        		)) ;
        
        $menu[4] = array(
        		'text' => '全局',
        		'label' => 'global',
        		'tab1' => array(
        				'text' => '全局',
        				'label' => 'global',
        				'children' => array(
                                //        array('text' => L('siteConfig'), 'url' => URL('admin/Global/siteopt')),
                                        array('text' => L('seoConfig'), 'url' => URL('admin/Global/siteseo')),
                                     //   array('text' => '导航配置', 'url' => URL('admin/Global/nav')),
                                   //     array('text' => L('domainConfig'), 'url' => URL('admin/Global/domain')),
                                    //   array('text' => L('registerConfig'), 'url' => URL('admin/Global/register')),
                                      //  array('text' => L('guanshuiConfig'), 'url' => URL('admin/Global/guanshui')),
                                    //    array('text' => L('creditConfig'), 'url' => URL('admin/Global/credit')),
                                   //     array('text' => L('announcementConfig'), 'url' => URL('admin/Global/announcement')),
                                    //    array('text' => L('emailConfig'), 'url' => URL('admin/Global/email')),
                                      //  array('text' => L('attachConfig'), 'url' => URL('admin/Global/attachconfig')),
                                   //     array('text' => L('auditConfig'), 'url' => URL('admin/Global/audit')),
                                     //   array('text' => L('weiboConfig'), 'url' => URL('admin/Global/weibo')),
                                    //    array('text' => L('areaConfig'), 'url' => URL('admin/Global/area')),
                                      //  array('text' => '附近功能配置', 'url' => URL('admin/Global/imagenearConfig')),
        						        array('text' => '广告管理', 'url' => URL('admin/Content/ad')),
        						  //      array('text' => '注册码管理', 'url' => URL('admin/Content/apply')),
        						        array('text' => '网站通信', 'url' => URL('admin/Site/siteManager')),
        						        array('text' => L('cacheClean'), 'url' => URL('admin/Index/cleanRuntime')),
        						      //  array('text' => '导入数据', 'url' => URL('admin/CopyDB/importData')),
        						        array('text' => '版本升级', 'url' => URL('admin/Update/index')),
        						        //array('text' => '发布版本', 'url' => URL('admin/PublishVersion/index')),
        						     //   array('text' => L('nodeManage'), 'url' => URL('admin/User/nodeManage')),
        		                        ),
        		                 ),
        );
        
        
        $menu[5] = array(
        		'text' => '区块',
        		'label' => 'block',
        		'tab2' => array(
        				'text' => '区块设置',
        				'label' => 'blockconf',
        				'children' =>  array(
        						array('text' => '区块分类', 'url' => URL('cms/BlockClassify/classify')),
        				 ),
        		),
        		'tab1' => array(
        				'text' => '区块管理',
        				'label' => 'blockmanager',
        				'children' => array(),
        		)) ;
        
        $menutree[] = $menu[1];
        $menutree[] = $menu[2];
        $menutree[] = $menu[3];
        $menutree[] = $menu[4];
        $menutree[] = $menu[5];
    //    $menutree[] = $menu[6];
        //权限处理
        $roleMenu = $this->_getMenu();
        if (!empty($roleMenu)) {
        	foreach ($roleMenu as $k => $v) {
        		$roleMenu[$k] = $v["title"];
        	}
        	foreach ($menutree as $k => $menu1) {
        		if ($menu1['label'] === 'sns') {
        			foreach ($menu1['tab2']['children'] as $k2 => $menu3) {
        				foreach ($menu3['children'] as $k3 => $menu4) {
        					if (($menu3['label'] === 'apps' || $menu3['label'] === 'plugin') && !in_array($menu4['text'], $appplugin)) {
        						continue;
        					}
        					if (in_array($menu4['text'], $roleMenu)) {
        						continue;
        					} else {
        						unset($menutree[$k]['tab2']['children'][$k2]['children'][$k3]);
        					}
        				}
        				if (empty($menutree[$k]['tab2']['children'][$k2]['children'])) {
        					unset($menutree[$k]['tab2']['children'][$k2]);
        				}
        			}
        			foreach ($menu1['tab1']['children'] as $k1 => $menu2) {
        				if (in_array($menu2['text'], $roleMenu)  ) {
        					continue;
        				} else {
        					unset($menutree[$k]['tab1']['children'][$k1]);
        					//$menutree[$k]['tab1']['children'][$k1]=array();
        				}
        			}
        		} else {
        			foreach ($menu1['tab1']['children'] as $k1 => $menu2) {
        				if (in_array($menu2['text'], $roleMenu)  ) {
        					continue;
        				} else {
        					 unset($menutree[$k]['tab1']['children'][$k1]);
        					//$menutree[$k]['tab1']['children'][$k1]=array();
        				}
        			}
        			foreach ($menu1['tab2']['children'] as $k1 => $menu2) {
        				if (in_array($menu2['text'], $roleMenu)  ) {
        					continue;
        				} else {
        					 unset($menutree[$k]['tab2']['children'][$k1]);
        					//$menutree[$k]['tab2']['children'][$k1]=array();
        				}
        			}
        		}
        		if (empty($menutree[$k]['tab2']['children']) && empty($menutree[$k]['tab1']['children'])  ) {
        			if ($menutree[$k]['tab2']['label'] !== 'manager' || !in_array('内容列表', $roleMenu)) {
        				unset($menutree[$k]);
        			}
        		} 
//         		else if (empty($menutree[$k]['tab1']['children']) &&empty($menutree[$k]['tab2']['children']) && !in_array('区块', $roleMenu)) {
//         			unset($menutree[$k]);
//         		}
        	}
        }
        foreach($menutree as $k=>$v){
           if(!empty($menutree[$k]['tab1']['children'])||!is_array($menutree[$k]['tab1']['children'])){
           	   $menutree[$k]['tab1']['children'] = $this->_update_array($menutree[$k]['tab1']['children'] );
           }
              
           if(!empty($menutree[$k]['tab2']['children'])||!is_array($menutree[$k]['tab1']['children'])){
               $menutree[$k]['tab2']['children'] = $this->_update_array($menutree[$k]['tab2']['children'] );
           }
        }
        // 是否显示 插件
        if(!empty($menutree[1]['tab2']['children'][0])){
        	$appplugin = array(L('appsList'), L('appsInstall'), L('installPlugin'), L('waitInstallPlugin'));
        	$addons = M('Addons');
        	$list = $addons->where("isMenu='1'")->select();
        	foreach ($list as $k => $v) {
        		$datachildren = array('text' => $v['pluginName'], 'url' => URL('admin/Plugin/adminMenu', array('name' => $v ['name'])));
        		$menutree[1]['tab2']['children'][0]['children'][] = $datachildren;
        	}
        }
        // 处理是否显示  应用
        if(!empty($menutree[1]['tab2']['children'][2])){
        	unset($datachildren);
        	$apps = model("App")->getAdminApp('app_name,app_alias,admin_entry');
        	foreach ($apps as $v) {
        		$datachildren = array('text' => $v['app_alias'], 'url' => URL($v ['app_name'] . '/' . $v ['admin_entry']));
        		$menutree[1]['tab2']['children'][2]['children'][] = $datachildren;
        	}
        }
        
        //处理区块列表显示 
       if(!empty($menutree[5]['tab2'])){
       	    $classify = M('cms_blockclassify')->order('id')->select();
       	    unset($data);
       	    foreach ($classify as $k => $v) {
       	    	$data[$k]['text'] = $v['classify_name'];
       	    	$data[$k]['url'] = URL('cms/Block/ajax_show', array('type' => 'classify', 'id' => $v['id']));
       	    }
       	    
       	    if (empty($classify)) {
       	    	$data = array();
       	    }
       	    $menutree[5]['tab1']['children']= $data;
       }
       	// 数组序列重组
       	$arr =array_values($menutree);
       	return $arr;
       // return $menutree;
    }

    /**
     * php 关联数组 转换为需要的 索引数组
     * @param unknown $menutree
     * @return unknown
     */
    private function _update_array($menutree) {
        foreach ($menutree as $k => $v) {
            if (empty($v['children'])) {
                $arr[] = $v;
            	//$arr = array_values($v);
            } else {
                $v['children'] = $this->_update_array($v['children']);
                 $arr[] = $v;
                //$arr = array_values($v);
            }
        }
        return $arr;
    }

    public function getMenuTree() {
        echo json_encode($this->menu3());
    }

}
